﻿<?php
require_once("__construct.php");
class SendMailClass {
	
	public function __construct() {
		
	}
	
	private function getNeeded() {
		$link = mysql_connect(DB_HOST_on, DB_USER_on, DB_PASS_on);
		if (!$link) {
			die('Could not connect: ' . mysql_error());
		}
	}
	
	public function catchNeeded() {
		$this->getNeeded();
	}
	
	public function htmlMail($to,$text,$subject,$fromMail=false,$fromName){
	/* 
		// användning 
		
	$text = "
	Nytt meddelande från hemsidan.<br />
	namn: ".$_POST['name']."<br />
	telefon: ".$_POST['tel']."<br />
	meddelande: <br />
	".$_POST['tel']."<br />
	";
	htmlMail('ziinloader@live.se',$text,'Nytt meddelande från hemsidan');
	
	*/
	$message = '
	<html>
	<head>
	  <title>'.utf8_decode($subject).'</title>
	</head>
	<body>
	  '.utf8_decode($text).'
	</body>
	</html>
	';
	$domain = str_replace('www.','',$_SERVER['HTTP_HOST']);
	if(!$fromMail) $fromMail = 'hemsidan@'.$domain;
	
	// To send HTML mail, the Content-type header must be set
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	
	// Additional headers
	$headers .= 'To: <'.$to.'>'. "\r\n";
	$headers .= 'From: '.utf8_decode($fromName).' <'.utf8_decode($fromMail).'>' . "\r\n";
	$headers .= 'Reply-To: '.utf8_decode($fromMail) . "\r\n";
	$headers .= 'X-Mailer: PHP/' . phpversion();
	
	// Mail it
	mail($to, $subject, $message, $headers);
}
	
}
?>